package com.orangelife.mobile.myhouse.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.curry.android.adapter.FatherAdapter;
import com.curry.orangelife.mobile.R;
import com.orangelife.mobile.myhouse.entity.IndustryEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by HeYuCan on 2016/7/15.
 */
public class CertOklvAdapter extends FatherAdapter {


    private Context mContext;
    private List<IndustryEntity.ApartmentsBean> mList = new ArrayList<>();

    public CertOklvAdapter(Context context, List<IndustryEntity.ApartmentsBean> list) {
        this.mContext=context;
        this.mList = list;
    }

    @Override
    public BaseAdapter setList(List list) {
        this.mList = list;
        return null;
    }

    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_rv_cert_ok2, null);
            holder.mText = (TextView) convertView.findViewById(R.id.tvApartmentID);
            holder.ivType = (ImageView) convertView.findViewById(R.id.ivType);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }


        holder.mText.setText(mList.get(position).getHouseInfo());
        setTypeImage(holder.ivType, mList.get(position).getApartmentType());
        return convertView;
    }


    private void setTypeImage(ImageView iv, String type) {
        if ("1".equals(type)) {
            iv.setImageResource(R.drawable.ic_park);
        } else {
            iv.setImageResource(R.drawable.ic_apartment);
        }

    }


    class ViewHolder {
        TextView mText;
        ImageView ivType;

    }


}
